<template>
    <div class="hover-pos-container">
        <div class="hover-pos-bt" :style="{ '--x': x, '--y': y }"><span>HOVER</span></div>
    </div>
</template>

<script>

export default {
    name: "MousePositionButton",
    data() {
        return {
            offsetLeft: 0,
            offsetTop: 0,
            x: "0px",
            y: "0px",
        }
    },
    methods: {
        getPosition(e) {
            this.x = e.pageX - this.offsetLeft + "px";
            this.y = e.pageY - this.offsetTop + "px";
        },
    },
    mounted() {
        const bt = this.$el.querySelector(".hover-pos-bt");
        this.offsetLeft = bt.offsetLeft;
        this.offsetTop = bt.offsetTop;
        bt.addEventListener("mouseover", this.getPosition);
    },
    beforeUnmount() {
        const bt = this.$el.querySelector(".hover-pos-bt");
        bt.removeEventListener("mouseover", this.getPosition);
    },
}
</script>

<style scoped>
.hover-pos-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.hover-pos-bt {
    width: 300px;
    height: 100px;
    background-color: #444;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    display: grid;
    place-items: center;
}

.hover-pos-bt::after {
    content: '';
    width: 0px;
    height: 0px;
    position: absolute;
    top: var(--y);
    left: var(--x);
    translate: -50% -50%;
    background-color: #43b384;
    border-radius: 50%;
    transition: 0.6s ease-out, left 0s, top 0s;
}

.hover-pos-bt:hover::after {
    width: 600px;
    height: 600px;
}

.hover-pos-bt>span {
    font-size: 25px;
    letter-spacing: 2px;
    color: #fff;
    pointer-events: none;
    z-index: 1;
}
</style>
